package com.azdebugit.suanfa.test.diedai;

public class ZuiDaGongYue {
    public static int gcd(int a, int b) {

        if (a <= 0 || b <= 0) {//预防错误
            return 0;
        }
        int temp;
        if (a < b) { //交换a,b保证a大于b
            temp = a;
            a = b;
            b = a;
        }
        //迭代计算
        while (b > 0) {  //边界条件
            temp = a % b;
            a = b;
            b = temp;
        }
        return a;//最大公约数
    }

    public static void main(String[] args) {
        System.out.println(gcd(128,28));
    }
}
